package com.qf.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsCommentMapper;
import com.qf.pojo.DtsComment;
import com.qf.service.AdminCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AdminCommentServiceImpl implements AdminCommentService {
        @Autowired
    DtsCommentMapper commentMapper;

    @Override
    public Map<String, Object> findPage(Integer page, Integer limit, String sort, String order, Integer valueId, Integer userId, List<Integer> brandsId) {
        IPage<DtsComment> iPage = new Page<>(page,limit);

        QueryWrapper wrapper = new QueryWrapper();

        if("desc".equalsIgnoreCase((order))){
            wrapper.orderByDesc("c."+sort);
        }else{
            wrapper.orderByAsc("c."+sort);
        }
        //用户id条件
        if(userId!=null){
            wrapper.eq("c.user_id",userId);
        }
        if(valueId!=null){
            wrapper.eq("c.value_id",valueId);
        }

        if(brandsId!=null && brandsId.size()>0){
            wrapper.in("g.brand_id",brandsId);
        }

        commentMapper.selectCommentPage (iPage,wrapper);

        Map<String,Object> data = new HashMap<>();

        data.put("total",iPage.getTotal());
        data.put("items",iPage.getRecords());
        return data;


    }

    @Override
    public void delete(DtsComment dtsComment) {

        commentMapper.deleteById(dtsComment.getId());
    }


}
